package com.quanxiaoha.weblog.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quanxiaoha.weblog.common.domain.dos.ArticleContentDO;

public interface ArticleContentMapper extends BaseMapper<ArticleContentDO> {

    /**
     * 根据文章id删除其文章内容
     *
     * @param articleId
     */
    default void delByArticleId(Long articleId) {
        this.delete(new LambdaQueryWrapper<ArticleContentDO>().eq(ArticleContentDO::getArticleId, articleId));
    }

    /**
     * 根据文章id获取其文章详情
     *
     * @param articleId
     * @return
     */
    default ArticleContentDO getByArticleId(Long articleId) {
        return this.selectOne(new LambdaQueryWrapper<ArticleContentDO>().eq(ArticleContentDO::getArticleId, articleId));
    }


    default int updateByArticleId(ArticleContentDO articleContentDO) {
//        LambdaQueryWrapper<ArticleContentDO> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(ArticleContentDO::getArticleId,articleContentDO.getId());
//        return update(articleContentDO, wrapper);
        return update(articleContentDO, new LambdaQueryWrapper<ArticleContentDO>().eq(ArticleContentDO::getArticleId, articleContentDO.getArticleId()));
    }

}